<template>
  <h2>当前求和为：{{ sum }}</h2>
  <button @click="sum++">点我加一</button>
  <hr>
  <h2>当前信息为：{{ msg }}</h2>
  <button @click="msg+='!'">修改信息</button>
  <h2>姓名：{{ person.name }}</h2>
  <h2>年龄：{{ person.age }}</h2>
  <button @click="person.age++">增加年龄</button>
  <button @click="person.name+='~`'">修改姓名</button>
  <h2>职业：{{ person.work.post }}</h2>
  <h2>薪水：{{ person.work.money }}K</h2>
  <button @click="person.work.money++">增加薪水</button>
  <button @click="person.work.post+='+'">修改职位</button>
</template>

<script>
import {reactive, ref, watchEffect} from "vue";

export default {
  name: "Demo",
  setup() {
    let sum = ref(0)
    let msg = ref("你好啊")
    let person = reactive({
      name: '张三',
      age: 18,
      work: {
        money: 100,
        post: "后端开发"
      }

    })
    //监视
    /*watch(
    sum,
    function (newValue,oldValue){
      console.log("sum值变化了,以前是"+oldValue+",现在是"+newValue)
    }
    )*/

    //智能监视，监视里面用到的数据
    watchEffect(
      function (){
        sum.value
         console.log("watchEffect执行了")
      }
    )

    return {
      sum,
      msg,
      person,
    }
  }
}
</script>

<style scoped>

</style>
